"""插入排序"""
lis4 = [3, 4, 6, 2, 9, 1, 0, 7, 5, 8]
for i in range(1, len(lis4)):
    index = i
    value = lis4[i]
    while index>0 and lis4[index-1] > value:
        lis4[index] = lis4[index-1]
        index-=1
    lis4[index] = value
print('lis4的插入排序法：',lis4)

lis = [3, 4, 6, 2, 9, 1, 0, 7, 5, 8]

def insert_sort(li):
    for i in range(1, len(li)):
        tmp = li[i]
        j = i -1
        while j >= 0 and li[j] > tmp:
            li[j+1] = li[j]
            j -= 1
        li[j+1] = tmp
insert_sort(lis)
print(lis)


import random

li = [random.randint(1, 200) for ii in range(13)]
print(li)
n = len(li)

for i in range(1, n):
    j = i
    while j > 0 and li[j] < li[j - 1]:
        li[j], li[j - 1] = li[j - 1], li[j]
        j -= 1
print(li)

















